package test00.test07;

import test00.test05.t01.Student;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author lzp
 * @Date 2024-04-14
 */
public class Test {
    public static void main(String[] args) {

        Student[] stu ={
                new Student("张三",13),
                new Student("张三",11),
                new Student("李三",12),
                new Student("李四",15),
                new Student("李一",18),
                new Student("李二",19),
                new Student("王五",20),
                new Student("赵六",21)
        };

        //创建 Stream 对象
        Stream<Student> stream =Stream.of(stu);

        //需要先排序
//        stream.sorted(((o1, o2) -> o2.getAge() - o1.getAge())).filter((t)->{
//            if (t.getName().startsWith("李") && t.getAge() < 18){
//                System.out.println(t);
//            }
//            return false;
//        }).forEach(System.out::println);


        stream.sorted(((o1, o2) -> o2.getAge() - o1.getAge())).filter((t) -> {
            if (t.getName().startsWith("李") && t.getAge() < 18) {
                //System.out.println(t);
                return true;
            }
            return false;
        }).map(Student::getName).limit(2).forEach(System.out::println);



    }
}
